# Maintainer: Olliver Schinagl <oliver@schinagl.nl>
_luaversions="5.1 5.2 5.3 5.4"
pkgname=lua-dbus_proxy
_rockname="${pkgname#lua-*}"
pkgver=0.10.3
pkgrel=1
pkgdesc="Simple API around GLib's GIO:GDBusProxy built on top of lgi"
url="https://github.com/stefano-m/lua-dbus_proxy"
arch="all"
license="Apache-2.0"
depends="dbus lua-lgi"
subpackages="$pkgname-doc"
makedepends="luarocks gobject-introspection-dev"
options="!check" # Tests require running dbus server to interact with
source="$pkgname-$pkgver.tar.gz::https://github.com/stefano-m/lua-dbus_proxy/archive/v$pkgver.tar.gz"

for _luaversion in ${_luaversions}; do
	makedepends="$makedepends lua$_luaversion-dev lua$_luaversion-lgi"
	subpackages="$subpackages lua$_luaversion-${_rockname}:_subpackage"
done

build() {
	for _luaversion in ${_luaversions}; do
		msg "Building for Lua $_luaversion"
		"luarocks-$_luaversion" \
			CC="$CC" \
			CFLAGS="$CFLAGS -fPIC" \
			LUA_INCDIR="$(pkg-config --variable=includedir "lua$_luaversion")" \
			LUA_LIBDIR="$(pkg-config --variable=libdir "lua$_luaversion")" \
			LUA_VERSION="$_luaversion" \
			make --tree="./build-$_luaversion" \
			--deps-mode=none \
			"rockspec/$_rockname-$pkgver-"*".rockspec"
	done
}

package() {
	mkdir -p "$pkgdir/usr/share/doc/$pkgname/"
	cp -r "docs/" "$pkgdir/usr/share/doc/$pkgname/"
}

_subpackage() {
	_luaversion="${subpkgname%-"$_rockname"}"
	_luaversion="${_luaversion#lua*}"
	pkgdesc="$pkgdesc - for Lua $_luaversion"
	depends="$depends lua$_luaversion lua$_luaversion-lgi"
	install_if="lua$_luaversion $pkgname=$pkgver-r$pkgrel"

	for _luascript in "$builddir/build-$_luaversion/share/lua/$_luaversion/$_rockname/"*.lua; do
		install -D -m 0644 \
			-t "$subpkgdir/usr/share/lua/$_luaversion/$_rockname" \
			"$_luascript"
	done
}

sha512sums="
5284427abf56cd612989ed3e45ea9ea848b88f456f4ee2d34e96a2f91e1309ce7867bcbd6f218b4f034dca09dcfed68f00a9eb72666003dbd35c16710062387c  lua-dbus_proxy-0.10.3.tar.gz
"
